<?php
//前台商城类别控制器
namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;

class ListController extends CommonController
{ 
    
	//加载前台列表页
	public function index()
    {
		$tdata['port'] = $_GET['name'];
		$tdata['gid'] = $_GET['list'];
		$z = \DB::table("notice")->where('status','0')->get();
		$n = \DB::table("notice")->where('status','1')->get();
		$f = \DB::table("m_forum")->get();
		$g = \DB::table("m_genre")->get();
		$fl = \DB::table("friendlink")->get();
		$pic = \DB::table("m_pic")->get();
		$t = \DB::table("m_type")->get();
		$g1 = \DB::table("m_genre")->where("id",$tdata['gid'])->first();
		//获取改商类别标签信息
		$pag = \DB::table("m_pag")->where("gid",$tdata['gid'])->get();
		foreach($pag as $v){
			$data = explode("、", $v->values);
			foreach($data as $dv){
				if($tdata['port'] == $dv){
					$s = \DB::table("m_search")->where("gid",$tdata['gid'])->where($v->field,$tdata['port'])->get();
					$m = \DB::table("m_info")->where("gid",$tdata['gid'])->whereIn("status",["on","wait"])->get();
					$p = \DB::table("m_pag")->where("gid",$tdata['gid'])->where("field",'!=',$v->field)->get();
					return view("home.list",['forum'=>$f, 'notice'=>$n,'notices'=>$z, 'genre'=>$g, 'friendlink'=>$fl,
						'tdata'=>$tdata, 'genre1'=>$g1, 'type'=>$t, 'pag'=>$p, 'pic'=>$pic, 'minfo'=>$m,'search'=>$s]);
				}
			}
		}
		$m = \DB::table("m_info")->where("gid",$list)->whereIn("status",["on","wait"])->get();
		$s = \DB::table("m_search")->where("gid",$list)->get();
		return view("home.list",['forum'=>$f, 'genre'=>$g, 'notice'=>$n,'notices'=>$z, 'genre1'=>$g1, 'type'=>$t, 'friendlink'=>$fl, 'pag'=>$p, 'minfo'=>$m, 'pic'=>$pic, 'search'=>$s]);
		 
    }
	public function store(Request $request)
	{
		$tdata = $request->except(['_token']);
		$z = \DB::table("notice")->where('status','0')->get();
		$n = \DB::table("notice")->where('status','1')->get();
		$f = \DB::table("m_forum")->get();
		$g = \DB::table("m_genre")->get();
		$fl = \DB::table("friendlink")->get();
		$pic = \DB::table("m_pic")->get();
		$t = \DB::table("m_type")->get();
		$g1 = \DB::table("m_genre")->where("id",$tdata['gid'])->first();
		//获取改商类别标签信息
		$pag = \DB::table("m_pag")->where("gid",$tdata['gid'])->get();
		$s = \DB::table("m_search")->where("gid",$tdata['gid']);
		$p = \DB::table("m_pag")->where("gid",$tdata['gid']);
		foreach($pag as $v){
			$data = explode("、", $v->values);
			foreach($data as $dv){
				foreach($tdata as $k => $tv){
					if($v->field == $k && $tv == $dv){
						$s->where($k, $tv);
						$p->where("field",'!=',$k);
					}
				}
			}
		}
		$p = $p->get();
		$s = $s->get();
		$m = \DB::table("m_info")->where("gid",$tdata['gid'])->whereIn("status",["on","wait"])->get();
		return view("home.list",['forum'=>$f, 'notice'=>$n,'notices'=>$z, 'genre'=>$g, 'friendlink'=>$fl,
				'tdata'=>$tdata,'genre1'=>$g1, 'type'=>$t, 'pag'=>$p, 'pic'=>$pic, 'minfo'=>$m,'search'=>$s]);
	}
}
